

'''
-- 用户登录日志表    
CREATE TABLE user_login_log (
    log_id SERIAL PRIMARY KEY,    
    user_id INTEGER NOT NULL REFERENCES user_info(user_id),    
    login_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,     
    ip_address VARCHAR(20) NOT NULL,    
    user_agent VARCHAR(200) NOT NULL    
);

'''


class UserLoginLogTableMethod:

    def __init__(self, conn, cur):
        self.cursor = cur
        self.conn = conn


    def insert_user_login_log(self, user_id, ip_address, user_agent):
        try:
            sql = "INSERT INTO user_login_log (user_id, ip_address, user_agent) VALUES (%s, %s, %s)"
            val = (user_id, ip_address, user_agent)
            self.cursor.execute(sql, val)
            self.conn.commit()
            return True 
        except Exception as e:    
            print(e)
            return False
        
    def get_user_login_log(self, user_id):
        try:
            sql = "SELECT * FROM user_login_log WHERE user_id = %s"
            val = (user_id,)
            self.cursor.execute(sql, val)
            result = self.cursor.fetchall()
            return result
        except Exception as e:    
            print(e)
            return False
        